package cn.tqfeiyang.smartadmin.business.member.controller;

import cn.tqfeiyang.smartadmin.business.member.request.MemberLevelCreateDTO;
import cn.tqfeiyang.smartadmin.business.member.request.MemberLevelSearchDTO;
import cn.tqfeiyang.smartadmin.business.member.request.MemberLevelUpdateDTO;
import cn.tqfeiyang.smartadmin.business.member.response.MemberLevelDetailVO;
import cn.tqfeiyang.smartadmin.business.member.response.MemberLevelSearchVO;
import cn.tqfeiyang.smartadmin.business.member.service.MemberLevelService;
import cn.tqfeiyang.smartadmin.commons.pagination.PageData;
import cn.tqfeiyang.smartadmin.commons.validation.EntityId;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.module.support.operatelog.annotation.OperateLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 会员等级控制器
 *
 * @author tqfeiyang
 * @since 2024-08-15
 */
@RestController
@OperateLog
@Validated
@RequestMapping("/api/oa/memberLevel")
@Tag(name = "OA办公-会员等级")
public class MemberLevelController {

    /**
     * 会员等级服务
     */
    @Resource
    private MemberLevelService memberLevelService;

    /**
     * 查询会员等级
     *
     * @param dto 请求数据
     * @return 会员等级列表
     */
    @GetMapping("/search")
    @Operation(summary = "查询会员等级")
    public ResponseDTO<PageData<MemberLevelSearchVO>> selectPage(@Validated MemberLevelSearchDTO dto) {
        return ResponseDTO.ok(memberLevelService.selectPage(dto));
    }

    /**
     * 获取会员等级
     *
     * @param id 会员等级id
     * @return 会员等级信息
     */
    @GetMapping("/detail")
    @Operation(summary = "获取会员等级")
    public ResponseDTO<MemberLevelDetailVO> selectDetail(@RequestParam @EntityId Long id) {
        return ResponseDTO.ok(memberLevelService.selectDetail(id));
    }

    /**
     * 添加会员等级
     *
     * @param dto 请求数据
     * @return 会员等级信息
     */
    @PostMapping("/create")
    @Operation(summary = "添加会员等级")
    public ResponseDTO<MemberLevelDetailVO> create(@RequestBody @Validated MemberLevelCreateDTO dto) {
        Long id = memberLevelService.create(dto);
        return ResponseDTO.ok(memberLevelService.selectDetail(id));
    }

    /**
     * 修改会员等级
     *
     * @param id 会员等级id
     * @param dto 请求数据
     * @return 会员等级信息
     */
    @PostMapping("/update")
    @Operation(summary = "修改会员等级")
    public ResponseDTO<MemberLevelDetailVO> update(@RequestParam @EntityId Long id, @RequestBody @Validated MemberLevelUpdateDTO dto) {
        memberLevelService.update(id, dto);
        return ResponseDTO.ok(memberLevelService.selectDetail(id));
    }

    /**
     * 删除会员等级
     *
     * @param id 会员等级id
     */
    @PostMapping("/delete")
    @Operation(summary = "删除会员等级")
    public ResponseDTO<String> delete(@RequestParam @EntityId Long id) {
        memberLevelService.delete(id);
        return ResponseDTO.ok();
    }
}
